package com.freshfresh.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.freshfresh.activity.R;


public class GridTypeAdapter extends BaseAdapter {
	List<Map<String, Object>> apk_list;
	LayoutInflater inflater;
	private int[] ids = { R.drawable.xinpintuijian_03, R.drawable.shuiguo_03, R.drawable.haiwaiyinpin_03, R.drawable.roulei_03, R.drawable.shucaizhaipei_03, R.drawable.haiwaiyinpin_03, R.drawable.qiuji_03, R.drawable.weishengsu, R.drawable.baobaozuiai_03 };
	public GridTypeAdapter(Context context, List<Map<String, Object>> apk_list) {
		this.apk_list = apk_list;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return apk_list.size();
	}

	public void notifyData(List<Map<String, Object>> apk_list) {
		this.apk_list=apk_list;
		this.notifyDataSetChanged();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return apk_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Map<String, Object> entity = apk_list.get(position);
		ViewHolderGt holder;
		if (convertView == null) {
			holder = new ViewHolderGt();
			convertView = inflater.inflate(R.layout.it_search, null);
			holder.tv_icon = (ImageView) convertView
					.findViewById(R.id.tv_icon);
			holder.tv_title = (TextView) convertView
					.findViewById(R.id.tv_title);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolderGt) convertView.getTag();
		}
		 holder.tv_icon.setImageResource(ids[position]);

		if (entity.get("name") != null) {
			holder.tv_title.setText(entity.get("name").toString());
		}


		return convertView;
	}

	class ViewHolderGt {
		ImageView tv_icon;// 图标
		TextView tv_title;// 名称

	}
}
